package com.xhui.vimarket.zkplus.zul.attr.mod.impl;
import java.util.List;
import java.util.Map;

import org.directwebremoting.util.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Div;

import com.xhui.crm.common.vo.RetVO;com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.acom.xhui.vimarket.zkplusst;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrTmpl;
import com.xhui.vcom.xhui.vimarket.zkpluszul.attr.bean.ValiVo;
import com.xhui.vimarket.zkplus.zul.attr.mod.AttrCcom.xhui.vimarket.zkplus/**
 * @版权：福富软件 版权所有 (c) 2010
 * @文件：com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrPanelComp.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：属性控件接口
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public final class AttrDivComp extends AttrBaseComp {
    
    /**
     * 实例.
     */
    private static AttrDivComp inst   = new AttrDivComp();
    
    /**
     * 日志.
     */
    private static Logger      logger = Logger.getLogger(AttrDivComp.class);
    
    /**
     * 构造函数. 
     */
    private AttrDivComp() {
    }
    
    /**
     * 获取实例.
     * 
     * @return AttrBaseComp
     */
    public static AttrDivComp instance() {
        return AttrDivComp.inst;
    }
    
    /**
     * 生成组件.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 组件模板
     * @param comp 显示容器组件
     */
    @Override
    public void create(final AttrExt attrExt, final AttrTmpl attrTmpl, final Component comp) {
        super.create(attrExt, attrTmpl, comp);
        // Div
        final Div div = new Div();
        div.setWidth("100%");
        div.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
        div.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
        div.setParent(comp);
        
        // sub comp
        final int sum = attrTmpl.getAttrTmplListCount();
        for (int i = 0; i < sum; i++) {
            Div div2 = new Div();
            div2.setStyle("float:left;");
            div2.setParent(div);
            /*if (!attrTmpl.isDisplay()
                || AttrConstants.DISPLAY_STYLE_PANEL_HIDE.equals(attrTmpl.getDisplayStyle())) {
                div2.setVisible(false); // 隐藏
            }*/
            final AttrTmpl subAttrTmpl = attrTmpl.getAttrTmplList(i);
            AttrCompFactory.getInst(subAttrTmpl.getDisplayMode())
                .create(attrExt, subAttrTmpl, div2);
        }
        
        if (AttrDivComp.logger.isDebugEnabled()) {
            attrExt.appendInnerComp("</div>");
        }
        
        super.afterCreate(attrExt, attrTmpl, comp);
        
    }
    
    /**
     * 设置值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param attrInstList 属性实例
     */
    @Override
    public void setValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList, Map<String, Integer> attrViewMap) {
        super.setValue(attrExt, comp, attrInstList, attrViewMap);
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            AttrCompFactory.getInstByComponent(subRootComp).setValue(attrExt, subRootComp,
                attrInstList, attrViewMap);
    com.xhui.vimarket.zkplus   
    /**
     * {@inheritDoc}
     * @see com.xhui.com.xhui.vimarket.d.AttrComp
     * #setRemovedValue(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component, java.util.List)
     * @author wuyx
     * 2011-4-8 wuyx
     */
    public void setRemovedValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList) {
        super.setRemovedValue(attrExt, comp, attrInstList);
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            AttrCompFactory.getInstByComponent(subRootComp).setRemovedValue(attrExt, subRootComp,
                atcom.xhui.vimarket.zkplus       }
    }
    
    /**
     * {@inheritDcom.xhui.vimarket.zkpluse com.xhui.vimarket.zkplus.zul.attr.mod.AttrComp
     * #setDisabledValue(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component, java.util.List)
     * @author wuyx
     * 2011-4-8 wuyx
     */
    public void setDisabledValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList) {
        super.setRemovedValue(attrExt, comp, attrInstList);
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            AttrCompFactory.getInstByComponent(subRootComp).setDisabledValue(attrExt, subRootComp,
                attrInstList);
        }
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                final ArrayList<AttrInst> subRetList = AttrCompFactory.getInstByComponent(
                    subRootComp).getValue(attrExt, subRootComp);
                if (subRetList != null) {
                    retList.addAll(subRetList);
                }
    com.xhui.vimarket.zkplus    }
        return retList;
    }

    com.xhui.vimarket.zkplusnheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp#signRuleHint(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2012-2-16 wuyx
     */
    @Override
    public ArrayList<ValiVo> signRuleHint(AttrExt attrExt, Component comp) {
        super.signRuleHint(attrExt, comp);
        final ArrayList<ValiVo> retList = new ArrayList<ValiVo>();
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                final ArrayList<ValiVo> subRetList = AttrCompFactory.getInstByComponent(
                    subRootComp).signRuleHint(attrExt, subRootComp);
                if (subRetList != null) {
                    retList.addAll(subRetList);
                }
            }
        }
        return retList;
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                final ArrayList<AttrInst> subRetList = AttrCompFactory.getInstByComponent(
                    subRootComp).getNullValue(attrExt, subRootComp);
                if (subRetList != null) {
                    retList.addAll(subRetList);
                }
            }
        }
        return retList;
    }
    
    /**
     * 取空值属性实例.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 模板
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final AttrTmpl attrTmpl) {
        super.getNullValue(attrExt, attrTmpl);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        for (final AttrTmpl subAttrTmpl : attrTmpl.getAttrTmplList()) {
            final ArrayList<AttrInst> subRetList = AttrCompFactory.getInst(
                subAttrTmpl.getDisplayMode()).getNullValue(attrExt, subAttrTmpl);
            retList.addAll(subRetList);
        }
        return retList;
    }
    
    /**
     * 清空值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     */
    @Override
    public void clean(final AttrExt attrExt, final Component comp) {
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                AttrCompFactory.getInstByComponent(subRootComp).clean(attrExt, subRootComp);
            }
        }
    }
    
    /**
     * 设置为不允许修改.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param tflag 设置值，true/false
     */
    @Override
    public void setDisabled(AttrExt attrExt, Component comp, boolean tflag) {
        super.setDisabled(attrExt, comp, tflag);
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                AttrCompFactory.getInstByComponent(subRootComp).setDisabled(attrExt, subRootCcom.xhui.vimarket.zkplus           tflag);
            }
        }
    com.xhui.vimarket.zkplus*
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #validate(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-22 wuyx
     */
    @Override
    public List<RetVO> validate(AttrExt attrExt, Component comp) {
        final ArrayList<RetVO> retList = new ArrayList<RetVO>();
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                final List<RetVO> subRetList = AttrCompFactory.getInstByComponent(subRootComp)
                    .validate(attrExt, subRootComp);
                if (subRetList != null) {
                    retList.addAll(subRecom.xhui.vimarket.zkplus          }
            }
        }
        return retLicom.xhui.vimarket.zkplus 
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrBaseComp
     * #refreshButtonText(com.xhui.vimarket.zkplus.zul.attr.AttrExt, org.zkoss.zk.ui.Component)
     * @author wuyx
     * 2011-3-24 wuyx
     */
    @Override
    public void refreshButtonText(AttrExt attrExt, Component comp, final List<AttrInst> attrInstList) {
        final ArrayList<RetVO> retList = new ArrayList<RetVO>();
        // 自身不实例化，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                AttrCompFactory.getInstByComponent(subRootComp).refreshButtonText(attrExt,
                    subRootComp, attrInstList);
            }
        }
    }
    
    /**
com.xhui.vimarket.zkplus.
     * 
     * @param comp 组件
     * @param attrViewMap 信息是否可见映照
     */
    @Override
    /**
     * {@inheritDoc}
     * @see com.xhui.vimarket.zkplus.zul.attr.mod.AttrComp
     * #setAttrView(org.zkoss.zk.ui.Component, Map<String, Integer>)
     * @author chenmh
     * 2011-6-16 chenmh
     */
    public void setAttrView(Component comp, Map<String, Integer> attrViewMap) {
        super.setAttrView(comp, attrViewMap);
        // 自身不隐藏，取下级数据
        // div
        final List<Component> subList = comp.getChildren();
        final int sum = subList == null ? 0
            : subList.size();
        AttrDivComp.logger.debug("subHboxList size:" + sum);
        for (int i = 0; i < sum; i++) {
            final Component subRootComp = subList.get(i).getFirstChild();
            if (subRootComp != null) {
                AttrCompFactory.getInstByComponent(subRootComp).setAttrView(subRootComp,
                    attrViewMap);
            }
        }
    }
    
}
